package fan.com.httpframe.app;

import android.support.multidex.MultiDexApplication;


/**
 * Created by wu on 16/4/7.
 */
public class BaseAppContext extends MultiDexApplication {
    private static BaseAppContext appContext;
    public String host;
    public void onCreate() {
        super.onCreate();
        appContext = this;
    }

    public static BaseAppContext getInstance() {
        return appContext;
    }

    /**
     * 清除app缓存
     */
    public void clearAppCache() {
        DataCleanManager.cleanDatabases(this);
        // 清除数据缓存
        DataCleanManager.cleanInternalCache(this);
        // 2.2版本才有将应用缓存转移到sd卡的功能
        if (isMethodsCompat(android.os.Build.VERSION_CODES.FROYO)) {
            DataCleanManager.cleanCustomCache(MethodsCompat
                    .getExternalCacheDir(this));
        }

    }

    @Override
    public void onTrimMemory(int level) {
        super.onTrimMemory(level);
    }

    @Override
    public void onLowMemory() {
        super.onLowMemory();


    }

    /**
     * 判断当前版本是否兼容目标版本的方法
     *
     * @param VersionCode
     * @return
     */
    public static boolean isMethodsCompat(int VersionCode) {
        int currentVersion = android.os.Build.VERSION.SDK_INT;
        return currentVersion >= VersionCode;
    }


    public void setHost(String host) {
        this.host = host;
    }

}
